home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / dev / src / expat-src.lha / expat-1.95.2 / xmlwf / codepage.c next >
Encoding:
C/C++ Source or Header  |  2001-07-28  |  1.2 KB  |  66 lines

  1. /*
  2. Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
  3. See the file COPYING for copying permission.
  4. */
  5.  
  6. #include "codepage.h"
  7.  
  8. #ifdef WIN32
  9. #define STRICT 1
  10. #define WIN32_LEAN_AND_MEAN 1
  11.  
  12. #include <windows.h>
  13.  
  14. int codepageMap(int cp, int *map)
  15. {
  16.   int i;
  17.   CPINFO info;
  18.   if (!GetCPInfo(cp, &info) || info.MaxCharSize > 2)
  19.     return 0;
  20.   for (i = 0; i < 256; i++)
  21.     map[i] = -1;
  22.   if (info.MaxCharSize > 1) {
  23.     for (i = 0; i < MAX_LEADBYTES; i++) {
  24.       int j, lim;
  25.       if (info.LeadByte[i] == 0 && info.LeadByte[i + 1] == 0)
  26.         break;
  27.       lim = info.LeadByte[i + 1];
  28.       for (j = info.LeadByte[i]; j < lim; j++)
  29.     map[j] = -2;
  30.     }
  31.   }
  32.   for (i = 0; i < 256; i++) {
  33.    if (map[i] == -1) {
  34.      char c = i;
  35.      unsigned short n;
  36.      if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
  37.                      &c, 1, &n, 1) == 1)
  38.        map[i] = n;
  39.    }
  40.   }
  41.   return 1;
  42. }
  43.  
  44. int codepageConvert(int cp, const char *p)
  45. {
  46.   unsigned short c;
  47.   if (MultiByteToWideChar(cp, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS,
  48.                   p, 2, &c, 1) == 1)
  49.     return c;
  50.   return -1;
  51. }
  52.  
  53. #else /* not WIN32 */
  54.  
  55. int codepageMap(int cp, int *map)
  56. {
  57.   return 0;
  58. }
  59.  
  60. int codepageConvert(int cp, const char *p)
  61. {
  62.   return -1;
  63. }
  64.  
  65. #endif /* not WIN32 */
  66.